package org.lw.controller;

import org.lw.Entity.User;
import org.lw.response.ApiResponse;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.NoSuchElementException;

@RestController
@RequestMapping("/hello")
public class HelloController {
    @GetMapping("/spring")
   public String  saySpring(){

        return "springMVC";
   }
    @GetMapping("/user/{id}/{name}")
    public ResponseEntity<ApiResponse<User>> sayUser(@PathVariable("id") int id,@PathVariable("name") String name){
        System.out.println(id+name);
        if (name.equals("liuwei"))
           return ResponseEntity.ok().body(new ApiResponse<>(200,"返回给前端的数据",new User(name,id)));
        else
            throw  new NoSuchElementException("No Such User");
    }
    @PostMapping("/user")
    public ResponseEntity<ApiResponse<User>> sayUser2(@RequestBody User user){
        System.out.println(user);
        return ResponseEntity.ok(new ApiResponse<>(200,"success",user));
    }

}
